///@file NodeGroup.cpp
///@brief Implementation of the class managing a group of nodes
///@author Arnaud Duval
///@version 0.0
///@date 2010/02/26

#include "NodeGroup.h"

///@brief Default constructor
NodeGroup::NodeGroup()
{

}

///@brief Constructor specifying the name of the group
///@param theName The ame of the group
NodeGroup::NodeGroup(std::string theName)
{
    name = theName;
}

///@brief destructor
NodeGroup::~NodeGroup()
{

}

///@brief Add a Node to the group
///@param n Pointer to te Node to add
void NodeGroup::AddNode(Node* n)
{
    nodes.push_back(n);
}

///@brief Remove a Node from the group
///@param n Pointer to the node to remove
void NodeGroup::RemoveNode(Node* n)
{
    std::list<Node*>::iterator lit = nodes.begin();
    while(lit != nodes.end())
    {
        if((*lit) == n)
            nodes.erase(lit);
        ++lit;
    }
}

///@brief Return the name of the group
std::string NodeGroup::GetName()
{
    return name;
}

///@brief Overload of << operator
///@param s Out stream
///@param g NodeGroup object to put in te out stream
std::ostream& operator << (std::ostream& s, const NodeGroup& g)
{
    s << g.name << "\n";
    for(std::list<Node*>::const_iterator it = g.nodes.begin() ; it != g.nodes.end() ; ++it)
    {
        s << **it << "\n";
    }
    return s;
}
